package algorithms.heap;

import org.junit.Test;

import algorithms.Util;
import algorithms.tree.BinaryNode;

public class TestHeap {
	@Test
	public void testHeapSort() {
		Integer[] a = { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 };
		HeapSort sort = new HeapSort();
		Integer[] res = sort.sort(a);
		Util.print(res);
	}

	@Test
	public void testHeapify() {
		Heapify h = new Heapify();
		Integer[] ac = { 1, 25, 6, 9, 100, 20, 30 };
		h.buildHeapFromArray(ac); // 100,25,30,9,1,20,6
		for (int i = ac.length - 1; i >= 0;) {
			System.out.println();
			h.heapify(ac, i--, ac.length);
		}
		Util.print(ac);
	}

	@Test
	public void testLeftistHeap() {
		Integer a[] = { 9, 4, 16, 7, 10, 2, 14, 3, 8, 1 };
		LeftistMinHeap heap = Util.generateLeftMinHeap(a);
		System.out.println(heap);
		BinaryNode<Integer> popNode = heap.pop();
		while (popNode != null) {
			System.out.print(popNode.getKey() + ",");
			popNode = heap.pop();
		}
		Integer a2[] = { 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 };
		heap = Util.generateLeftMinHeap(a2);
		System.out.println(heap);
	}

	@Test
	public void testSkewHeap() {
		Integer a2[] = { 1, 2, 3, 4, 7, 8, 9, 10, 14, 16 };
		SkewHeap heap = Util.generateSkewHeap(a2);
		System.out.println(heap);
		BinaryNode<Integer> popNode = heap.pop();
		while (popNode != null) {
			System.out.print(popNode.getKey() + ",");
			popNode = heap.pop();
		}
	}
}
